﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace NFAPI.Configuration
{
    public class NetflixServiceConfigurationSection : ConfigurationSection
    {
        [ConfigurationProperty("apikey", IsRequired = true)]
        public string APIKey
        {
            get { return (string)base["apikey"]; }
            set { base["apikey"] = value; }
        }

        [ConfigurationProperty("secret", IsRequired = false)]
        public string Secret
        {
            get { return (string)base["secret"]; }
            set { base["secret"] = value; }
        }

        [ConfigurationProperty("applicationname")]
        public string ApplicationName
        {
            get { return (string)base["applicationname"]; }
            set { base["applicationname"] = value; }
        }

        [ConfigurationProperty("signaturemethod", DefaultValue="HMAC-SHA1")]
        public string SignatureMethod
        {
            get { return (string)base["signaturemethod"]; }
            set { base["signaturemethod"] = value; }
        }

        [ConfigurationProperty("tokenStoreType", IsRequired = true)]
        public string TokenStoreType
        {
            get { return (string)base["tokenStoreType"]; }
            set { base["tokenStoreType"] = value; }
        }

        public ITokenStore GetTokenStore()
        {
            try
            {
                return (ITokenStore)Type.GetType(TokenStoreType).GetConstructor(new Type[0]).Invoke(null);
            }
            catch
            {
                return null;
            }
        }
    }
}
